package com.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;


public class DateFormat 
{
	public static SimpleDateFormat dateFormat_YM=new SimpleDateFormat("yyyy-MM");
	public static SimpleDateFormat dateFormat_YMD=new SimpleDateFormat("yyyy-MM-dd");
	public static SimpleDateFormat dateFormat_YMD_Single=new SimpleDateFormat("yyyy-M-d");
	public static SimpleDateFormat dateFormat_YMD_WEEK=new SimpleDateFormat("yyyy-MM-dd E");
	public static SimpleDateFormat dateFormat_YMD_HM=new SimpleDateFormat("yyyy-MM-dd HH:mm");
	public static SimpleDateFormat dateFormat_YMD_HMS=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static SimpleDateFormat dateFormat_YMD_HM_Single=new SimpleDateFormat("yyyy-M-d H:m");
	public static SimpleDateFormat dateFormat_YMD_HMS_Single=new SimpleDateFormat("yyyy-M-d H:m:s");
	public static SimpleDateFormat dateFormat_YMD_HMS_MS=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
	public static SimpleDateFormat dateFormat_YMDHMSMS=new SimpleDateFormat("yyyyMMddHHmmssSSS");
	public static SimpleDateFormat dateFormat_WEEK=new SimpleDateFormat("EEE");
	public static SimpleDateFormat dateFormat_HM=new SimpleDateFormat("HH:mm");
	public static SimpleDateFormat dateFormat_HMS=new SimpleDateFormat("HH:mm:ss");
	public static SimpleDateFormat dateFormat_HMSMS=new SimpleDateFormat("HH:mm:ss:SSS");
	public static SimpleDateFormat dateFormat_HM_DOT=new SimpleDateFormat("yyyy.MM.dd HH:mm");
	

	public static void main(String[] args) 
	{
		System.out.println();
		
	}
	/**
	 * month range:1-12
	 * @param year
	 * @param month
	 * @return
	 */
	public  int getFirstDayInWeek(int year,int month)
	{
		Calendar calendar=Calendar.getInstance(Locale.CHINA);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month-1);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		String week=dateFormat_WEEK.format(calendar.getTime());
		//System.out.println("week="+week.charAt(2));
		//System.out.println("days="+days);
		return week.charAt(2);
	}
	/*
	 * month range:1-12
	 * 
	 */
	 public  int getLastDayOfMonth(int year, int month)
	    {
	      if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || 
	        (month == 8) || (month == 10) || (month == 12)) {
	        return 31;
	      }
	      if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
	        return 30;
	      }
	      if (month == 2) {
	        if (isLeapYear(year)) {
	          return 29;
	        }
	        return 28;
	      }

	      return 0;
	    }

	    public  boolean isLeapYear(int year)
	    {
	      return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
	    }
	  
}
